/*
 * @Author: qianmingtian
 * @Date: 2020-07-17 09:45:27
 * @LastEditors: qianmingtian
 * @LastEditTime: 2020-07-17 10:05:21
 * @FilePath: \qianmingtian.github.io\code\java\MultiThread\Account.java
 */
package MultiThread;

public class Account {
    private String no;
    private String balance;

    public Account(String no, String balance) {
        this.no = no;
        this.balance = balance;
    }

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public String getBalance() {
        return balance;
    }

    public void setBalance(String balance) {
        this.balance = balance;
    }

    // 取款方法
    public void withdraw(double money) {

        synchronized (this) {
            double before = Double.parseDouble(this.getBalance());
            double after = before - money;
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
                // TODO: handle exception
            }
            this.setBalance(String.valueOf(after));
        }
    }

}/*
  * @Author: qianmingtian
  * 
  * @Date: 2020-07-17 09:45:27
  * 
  * @LastEditors: qianmingtian
  * 
  * @LastEditTime: 2020-07-17 09:45:28
  * 
  * @FilePath: \qianmingtian.github.io\code\java\MultiThread\Account.java
  */
